﻿@{
    ViewBag.Title = "Checkin de Vuelta";
}
<br />
<div id="ui-dialog-participante">
    <div class="filtering">
        <form>
            Nombres:
            <input type="text" class="fnombres" />
            Apellidos:
            <input type="text" class="fapellidos" />
            C&oacute;digo:
            <input type="text" class="fcodigo" />
            <p class="centered">
                <button type="submit" class="ConsultarPButton">Consultar</button>
            </p>
        </form>
    </div>
    <div class="ParticipanteTable"></div>
</div>
<div id="BusTable"></div>
@section Scripts {
    <script type="text/javascript" src="~/Scripts/jfunciones-participante.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#BusTable').jtable({
                title: '@ViewBag.Title',
                paging: true,
                pageSize: 25,
                sorting: true,
                multiSorting: true,
                defaultSorting: 'noBus ASC',
                actions: {
                    listAction: '@Url.Action("BusList", "Bus")',
                    deleteAction: '@Url.Action("DeleteBus", "Bus")',
                    updateAction: '@Url.Action("UpdateBus", "Bus")',
                    createAction: '@Url.Action("CreateBus", "Bus")'
                },
                fields: {
                    idBus: {
                        key: true,
                        create: false,
                        edit: false,
                        list: false
                    },
                    pasajeros: {
                        title: '',
                        width: '2%',
                        sorting: false,
                        edit: false,
                        create: false,
                        display: function (busData) {
                            var $img = $('<img src="' + GetAppURL() + '/Content/images/distribuir.png" title="Agregar pasajeros" />');
                            //Abrir child table al hacer click
                            $img.click(function () {
                                $('#BusTable').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'Bus No. ' + busData.record.noBus + ' - Pasajeros',
                                        actions: {
                                            listAction: '@Url.Action("PasajeroList", "Bus")?idBus=' + busData.record.idBus + '&ruta=' + '@SWGeneracionE.Constantes.RUTABUS_VUELTA',
                                            deleteAction: '@Url.Action("DeletePasajero", "Bus")',
                                            updateAction: '@Url.Action("UpdatePasajero", "Bus")',
                                            createAction: '@Url.Action("CreatePasajero", "Bus")'
                                        },
                                        fields: {
                                            idBus: {
                                                type: 'hidden',
                                                defaultValue: busData.record.idBus
                                            },
                                            ruta: {
                                                type: 'hidden',
                                                defaultValue: '@SWGeneracionE.Constantes.RUTABUS_VUELTA'
                                            },
                                            idBusParticipante: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                list: false
                                            },
                                            codigo: {
                                                title: 'Pasajero',
                                                width: '5%',
                                                input: function (data) {
                                                    if (data.record) {
                                                        return '<input type="text" name="codigo" class="validate[required,maxSize[20]] checkin-participante" value="' + data.record.codigo + '" />' +
                                                               '<img src="' + GetAppURL() + '/Content/images/ID.png" title="Buscar Participante" onclick="BuscarParticipante(\'#ui-dialog-participante\');" />';
                                                    } else {
                                                        return '<input type="text" name="codigo" class="validate[required,maxSize[20]] checkin-participante" />' +
                                                               '<img src="' + GetAppURL() + '/Content/images/ID.png" title="Buscar Participante" onclick="BuscarParticipante(\'#ui-dialog-participante\');" />';
                                                    }
                                                }
                                            },
                                            nombre: {
                                                title: 'Nombre',
                                                create:false,
                                                edit: false
                                            },
                                            tipoDocumento: {
                                                title: 'Tipo Documento',
                                                create: false,
                                                edit: false
                                            },
                                            noDocumento: {
                                                title: 'No. Documento',
                                                create: false,
                                                edit: false
                                            }
                                        },
                                        formSubmitting: function (event, data) {
                                            return data.form.validationEngine('validate');
                                        },
                                        formClosed: function (event, data) {
                                            data.form.validationEngine('hide');
                                            data.form.validationEngine('detach');
                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    }
                                 );
                            });
                            return $img;
                        }
                    },
                    imprimir: {
                        title: '',
                        width: '2%',
                        sorting: false,
                        edit: false,
                        create: false,
                        display: function (data) {
                            var $img = $('<img src="' + GetAppURL() + '/Content/images/ver.png" title="Imprimir reporte" />');
                            //Abrir dialog de inscribir al hacer click
                            $img.click(function () {
                                window.open('@Url.Action("BusExportExcel", "Bus")?idBus=' + data.record.idBus + '&ruta=' + '@SWGeneracionE.Constantes.RUTABUS_VUELTA', 'Exportar a Excel');
                           });
                           return $img;
                       }
                    },
                    noBus: {
                        title: 'No. Bus',
                        inputClass: 'validate[required,custom[number]]'
                    },
                    descripcion: {
                        title: 'Descripción',
                        inputClass: 'validate[required,maxSize[50]]'
                    },
                    estado: {
                        title: 'Estado',
                        listClass: 'bold',
                        options: '@Url.Action("GetEstadoOptions", "Bus")'
                    },
                    capacidad: {
                        title: 'Capacidad',
                        inputClass: 'validate[required,custom[number]]'
                    }
                },
                formCreated: function (event, data) {
                    data.form.validationEngine();
                },
                formSubmitting: function (event, data) {
                    return data.form.validationEngine('validate');
                },
                formClosed: function (event, data) {
                    data.form.validationEngine('hide');
                    data.form.validationEngine('detach');
                }
            });

            $('#BusTable').jtable('load');
            LoadParticipante(false, '#ui-dialog-participante', 'checkin-participante', false);
        });
    </script>
}
